How to use Algolia to filter content.
author
as an attribute for faceting, then apply your string filters with the filters
parameter in your search
code:
price
attribute is a numeric attribute, not a string attribute.
<
, <=
, =
, !=
, >=
, and >
.
To allow users to retrieve books between a range, say 20, set a range filter:
publication_date
attribute has the formatted date for display, while the date_timestamp
attribute can be used for filtering.
filters
parameter to only retrieve some results. For example:
date_timestamp
greater than now minus one year.
<
, <=
, =
, !=
, >=
, and >
.
NOT
boolean operator:
store
and categories
.
Using this dataset, users could, for example, retrieve all books about politics in stock in The Corner Bookshop.
categories
and store
as attributes for faceting, apply string filters with the filters
parameter in your search
code:
is_available
boolean attribute in the example dataset to exclude all records where is_available
is false
. To do this, first declare is_available
as an attribute for faceting.
false
as 0
and true
as 1
. This means you can apply numeric filters for boolean attributes. With the example dataset, is_available=0
is the same as is_available:false
.
attributesForFaceting
._tags
attribute.
Using the example dataset, if users type “harry” with the search restricted to “non-fiction”, it would retrieve “Where the Buck Stops” because it has “non-fiction” in the _tags
attribute and contains the word “harry” in the record.
_tags
attribute. For example, fiction
translates into _tags:fiction
.
You can also use tagFilters
to do the same thing.
_tags
and custom attributes_tags
attribute or a custom attribute for faceting:
_tags
is a reserved attribute which means it automatically works as a string filter without you having to set it as an attribute for faceting or use the filterOnly
modifier._tags
isn’t searchable by default._tags
for non-filtering purposes, such as displaying in search results or computing counts of records that match the filters._tags
can only contain strings.null
values or missing attributes, what happens when your index contains an attribute that isn’t present in all records?
For example, consider an online bookstore where people can buy and rate books from 0 to 5. Any record without the rating
attribute is assumed to be unrated.
If you want users to search for both rated and unrated books in the same filter, you must modify your data.
To do this, you can take one of two approaches:
rating
attribute and value, others have a null rating
, and some don’t have a rating
attribute.
null
or nonexistent attribute is different from zero, which represents a book with the lowest rating.objectID
objectID
attribute as a filter-only facet.
This means you can use the filters
parameter to filter on objectID
.
This is helpful when you want to include or exclude specific records in the current search.
For example, to exclude the record with objectID
“1234”, use the filter NOT objectID:1234
in the filters
parameter of your search.
books
. The index has records that look like this: